<script>
import {closeUe, getUeStatus, restartUEServer} from "@/api/aihuman/log/log";

export default {
  name: "InstanceStatus",
  data() {
    return {
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        pageSizes: [10, 20, 30, 40, 50, 100],
      },
      tableData: [],
      tableOptions: {
        //新增按钮
        addBtn: false,
        header: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        refreshBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        stripe: false,
        selection: true,
        tip: false,
        // simplePage: false,
        searchMenuSpan: 8,
        border: true,
        index: true,
        indexWidth: 60,
        indexLabel: "序号",
        menuWidth: 100,
        menu: true,
        align: "left",
        menuAlign: "left",
        dialogWidth: "40%",
        dialogClickModal: false,
        dialogType: "drawer",
        span: 24,
        dialogCustomClass: "huilan-drawer-form",
        emptyText: this.$t('aicosCommon.notData'),
        column: [
          {
            label: "id",
            prop: "id",
            minWidth: 200,
            // search: true,
            searchSpan: 8,
            overHidden: true
          },
          {
            label: "projectId",
            prop: "projectId",
            minWidth: 200,
            // search: true,
            searchSpan: 8,
            overHidden: true
          },

          {
            label: "status",
            prop: "status"
          }
        ],
      },
      selectedList: [],
      serverInfo: {},
      serverid: ''
    }
  },
  created() {
    this.getList()
  },
  methods: {
    selectionChange(val) {
      this.selectedList = val
    },
    currentChange(current) {
      this.page.currentPage = current
      this.getList()
    },
    sizeChange(size) {
      this.page.pageSize = size
      this.getList()
    },
    closeFn(row) {
      closeUe({ueId: row.id, serverId: this.serverInfo.id}).then(res => {
        this.$message.success(res.data.msg)
        this.getList()
      })
    },
    getList() {
      this.$nextTick(async () => {
        this.loading=true
        let params = {}
        const {data} = await getUeStatus(params)
        console.log(data);
        this.tableData = data.data[0].ueInfo
        this.serverInfo = data.data[0].serverInfo
        this.loading=false
        // this.page.total = data.data.total
      })
    },
    restart() {
      this.$confirm('此次操作是一个很危险的动作，确定要点击吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'error'
      }).then(() => {
        restartUEServer({serverId: this.serverInfo.id}).then(res=>{
          this.$message.success(res.data.msg)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
      });


    }
  }
}
</script>

<template>
  <huilan-basic>
    <HuilanBasicToolbar style="margin-top: 0">

      <!--      <el-button type="danger" size="small" @click="batchRemove">
              批量删除
            </el-button>-->
      当前服务器信息：{{ serverInfo.serverName }}
      <el-button type="primary" size="small" icon="el-icon-caret-right" @click="restart">远程重启信令</el-button>
      <el-button type="primary" size="small" icon="el-icon-refresh" @click="getList">刷新</el-button>
    </HuilanBasicToolbar>
    <avue-crud
      ref="listRef"
      v-loading="loading"
      :option="tableOptions"
      :page.sync="page"
      :data="tableData"
      @current-change="currentChange"
      @size-change="sizeChange"
      @selection-change="selectionChange"
    >
      <template slot-scope="scope" slot="menu">
        <el-button type="text" @click="closeFn(scope.row)">关闭</el-button>
      </template>

    </avue-crud>
  </huilan-basic>
</template>

<style scoped lang="scss">

</style>
